﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using EzDesk.Core.ServiceImpl.Services;
using EzDesk.Utility.Web.Controllers;
using EzDesk.Utility.ServiceStatusInfo;

namespace EzDesk.ServiceHost.Controllers
{
    public class LoginController : EzDeskAppController
    {
        private CoreClientLoginService _loginService = new CoreClientLoginService();

        //
        // POST: /Login/
        // RETURN_TYPE: StatusInfo

        /// <summary>
        /// 给客户端的登录方法
        /// </summary>
        /// <returns></returns>
        public JsonResult Login(string userName, string password)
        {
            var userProfile = _loginService.Login(userName, password);
            var statusInfo = new StatusInfo();
            if (userProfile != null)
            {
                statusInfo.Data = new
                        {
                            UserProfie = userProfile
                        };
                FormsAuthentication.SetAuthCookie(userProfile.Id.ToString(), false);
            }
            else
            {
                statusInfo.Status = ServiceStatus.Error;
            }
            return Json(statusInfo);
        }

        //
        // GET: /Login/UserNameForLogin
        // todo: 需要的时候再实现

        /// <summary>
        /// 通过一个输入的字符串获得用户的合法登录名的方法
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        public JsonResult UserNameForLogin(string inputString)
        {
            throw  new NotImplementedException();
        }

    }
}
